﻿using System;
using System.Collections;
using System.Globalization;
using System.Windows.Data;

namespace WgpgGUI
{
    [ValueConversion(typeof(Object), typeof(Boolean))]
    public sealed class NullOrEmptyConverter : IValueConverter
    {
        public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value == null)
                return true;

            if (value is IList)
                return ((IList)value).Count == 0;

            if (value is String)
                return ((String)value).Length == 0;

            return false;
        }

        public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
